﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Reflection;
using SimpleRest.Core.Routing;

namespace SimpleRest.Core.Extensions.Routes
{
    public class XsdRoute: Route
    {
        public readonly Type ServiceType;
        public readonly Type XsdType;
        public readonly Configuration Configuration;
        internal readonly Route AssociatedRoute;
        public readonly string RouteUri;
        public readonly string HttpMethod;
        public Pipeline RoutePipeline { get; private set; }
        public const string TargetHttpMethod = "GET";

        /// <summary>
        /// Create operation xsd route.  This XSD route will associate itself to the operation, route, and xsdType passed in through the ctor.
        /// In the event that a request gets routed to this XSD route and should be redirected to the associated operation route it will redirect
        /// to the associated operation route.
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="associatedRoute">The associated route that will be rerouted to in the event a request needs to be rerouted.</param>
        /// <param name="xsdType"></param>
        public XsdRoute(Pipeline routePipeline, Configuration configuration, string routeUri, Route associatedRoute, Type xsdType)
            : base(routeUri.TrimEnd(new char[] { '/' }) + ".XSD", new XsdRouteHandler(routePipeline, TargetHttpMethod, xsdType, associatedRoute, configuration))
        {
            this.RoutePipeline = routePipeline;
            this.ServiceType = routePipeline.ServiceType;
            this.AssociatedRoute = associatedRoute;
            this.RouteUri = routeUri.TrimEnd(new char[] { '/' }) + ".XSD";
            this.XsdType = xsdType;

            this.Configuration = configuration;
        }
    }
}
